package com.spark.sniffer.plugin.plugins.define.trace;

import static net.bytebuddy.matcher.ElementMatchers.named;

import com.spark.sniffer.plugin.interceptor.InstanceMethodsInterceptPoint;
import com.spark.sniffer.plugin.interceptor.StaticMethodsInterceptPoint;
import com.spark.sniffer.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine;
import com.spark.sniffer.plugin.match.ClassMatch;
import com.spark.sniffer.plugin.match.HierarchyMatch;
import com.spark.sniffer.plugin.plugins.interceptor.JdbcConnectionInterceptor;

import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;

/**
 * java.sql.Connection插件
 * 
 * @author Cobe
 *
 */
public class JdbcConnectionPlugin extends ClassInstanceMethodsEnhancePluginDefine {

    @Override
    protected InstanceMethodsInterceptPoint[] getInstanceMethodsInterceptPoints() {
        return new InstanceMethodsInterceptPoint[] {new InstanceMethodsInterceptPoint() {
            @Override
            public ElementMatcher<MethodDescription> getMethodsMatcher() {
                return named("prepareStatement");
            }

            @Override
            public Class<?> getMethodsInterceptor() {
                return JdbcConnectionInterceptor.class;
            }

            @Override
            public boolean isOverrideArgs() {
                return true;
            }
        }};
    }

    @Override
    protected StaticMethodsInterceptPoint[] getStaticMethodsInterceptPoints() {
        return null;
    }

    @Override
    protected ClassMatch enhanceClass() {
        return HierarchyMatch.byHierarchyMatch(new String[] {"java.sql.Connection"});
    }

}
